package cn.school.controller.pay;

import cn.school.common.api.CommonPage;
import cn.school.common.api.CommonResult;
import cn.school.pay.service.IPayCertificateService;
import cn.school.pay.vo.PayCertificateInfoVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/payCertificate")
public class PayCertificateController {

    @Autowired
    private IPayCertificateService payCertificateService;

    /**
     * 支付配置
     */
    @RequestMapping(value = "/query",method= RequestMethod.POST)
    public CommonResult<CommonPage<PayCertificateInfoVO>> queryPayCertificateList(@RequestBody PayCertificateInfoVO vo){
        IPage<PayCertificateInfoVO> pageList = payCertificateService.queryPayCertificateList(vo);
        return CommonResult.success(CommonPage.restPage(pageList));
    }


    /**
     * 新增支付配置
     */
    @RequestMapping(value = "/add",method=RequestMethod.POST)

    public CommonResult<Integer> addPayCertificate(@RequestBody PayCertificateInfoVO vo){
        int num = payCertificateService.addPayCertificate(vo);
        if(num>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }


    /**
     * 修改支付配置
     */
    @RequestMapping(value = "/update",method=RequestMethod.POST)
    public CommonResult<Integer> updatePayCertificate(@RequestBody PayCertificateInfoVO vo){
        int num = payCertificateService.updatePayCertificate(vo);
        if(num>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * 删除支付配置
     */
    @RequestMapping(value = "/delete",method=RequestMethod.POST)
    public CommonResult<Integer> delPayCertificate(@RequestBody PayCertificateInfoVO vo){
        int num = payCertificateService.delPayCertificate(vo);
        if(num>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * 刷新缓存支付配置
     */
    @RequestMapping(value = "/refreshConfigCache",method=RequestMethod.POST)
    public CommonResult<Integer> refreshConfigCache(){
        int num = payCertificateService.refreshConfigCache();
        if(num>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
}
